package aishua.com.mytestapplist.hencoder;

import android.annotation.TargetApi;
import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.RectF;
import android.os.Build;
import android.util.AttributeSet;
import android.view.View;

/**
 * Created by aishua on 2018/1/9.
 */

public class HenCoderDrawRectView extends View {

    private Paint paint;
    public HenCoderDrawRectView(Context context) {
        super(context);
    }

    public HenCoderDrawRectView(Context context, AttributeSet attrs) {
        super(context, attrs);
    }

    public HenCoderDrawRectView(Context context, AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
    }

    @Override
    protected void onDraw(Canvas canvas) {
        super.onDraw(canvas);
        paint = new Paint();
        paint.setColor(Color.RED);
        canvas.drawRect(100,100,500,500,paint);
        drawHollowrect(canvas);

    }

    public void drawHollowrect(Canvas canvas){

        paint.setColor(Color.BLACK);
        paint.setStyle(Paint.Style.STROKE);
        paint.setAntiAlias(true);
        paint.setStrokeWidth(5);
        canvas.drawRect(600,100,1000,500,paint);
        drawPoint(canvas);
    }

    public void drawPoint(Canvas canvas){
        paint.setColor(Color.GREEN);
//        paint.setStrokeCap(Paint.Cap.ROUND);
        paint.setStrokeCap(Paint.Cap.BUTT);
//        paint.setStrokeCap(Paint.Cap.SQUARE);
        paint.setStrokeWidth(180);
        paint.setStrokeJoin(Paint.Join.ROUND);
       canvas.drawPoint(100,600,paint);
        drawOval(canvas);
    }

    public void drawOval(Canvas canvas){
        paint.setColor(Color.BLUE);
//        canvas.drawOval(100,600,500,1000,paint);
        paint.setStyle(Paint.Style.STROKE);
        paint.setStrokeWidth(10);
         canvas.drawOval(new RectF(100,600,700,1000),paint);
         drawLine(canvas);
    }

    public void drawLine(Canvas canvas){

        paint.setColor(Color.CYAN);
        paint.setStrokeWidth(100);
//        paint.setStrokeCap(Paint.Cap.ROUND);
        paint.setStrokeCap(Paint.Cap.SQUARE);
        canvas.drawLine(100,1100,900,1200,paint);
        drawRoundRect(canvas);

    }
    public void drawRoundRect(Canvas canvas){

        paint.setColor(Color.RED);
        paint.setStrokeWidth(5);
        canvas.drawRoundRect(new RectF(100,1200,500,1600),50,50,paint);
    }

}
